package com.saui.traceu.view;

import java.util.List;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.util.Log;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class TraceOverlay extends Overlay{
	//private int mRadius=6;
	private int mcolor=0;
	private long session_id;
	private Bitmap img = null;
	protected List<GeoPoint> geopoints=null;

	public TraceOverlay(List<GeoPoint> geopoints, int color)
	{
		this.geopoints=geopoints;
		this.mcolor=color;
	}
	
	public void setSessionId(long l)
	{
		this.session_id = l;
	}
	
	public long getSessionId(){
		return this.session_id;
	}
	
	public Bitmap getBitmap()
	{
		return img;
	}
	
	public void setBitmap(Bitmap bitmap)
	{
		this.img = bitmap;
	}
	
	public int getColor()
	{
		return mcolor;
	}

	
	/*
	 * This function is automatically called when the overlay is added to the mapview.
	 * THere is no specific call from our code.
	 * 
	 * (non-Javadoc)
	 * @see com.google.android.maps.Overlay#draw(android.graphics.Canvas, com.google.android.maps.MapView, boolean, long)
	 */
	@Override
	public boolean draw (Canvas canvas, MapView mapView, boolean shadow, long when)
	{
		Projection projection = mapView.getProjection();
	
		if (shadow == true)
		{
			
			for(int i=0,j=1; j<geopoints.size();i++,j++){
				
				//set color and stroke information
				Paint paint = new Paint();
				paint.setColor(mcolor);
				paint.setAntiAlias(true);
				paint.setStrokeWidth(5);
				paint.setAlpha(120);
				
				//get points to pixels
				Point point1 = new Point();
				projection.toPixels(geopoints.get(i), point1);
				Point point2 = new Point();
				projection.toPixels(geopoints.get(j), point2);
				
				//draw the line between the two points
				canvas.drawLine(point1.x, point1.y, point2.x,point2.y, paint);
				Log.v("update", "session" +session_id + "Point 1" + point1 + " p2 " + point2);
			
//				RectF oval1=new RectF(point1.x - mRadius,point1.y - mRadius,
//						point1.x + mRadius,point1.y + mRadius);
//				paint.setAlpha(255);
//				canvas.drawOval(oval1, paint);
//				
//				RectF oval=new RectF(point2.x - mRadius,point2.y - mRadius,
//				point2.x + mRadius,point2.y + mRadius);
//				/* end point */
//				paint.setAlpha(255);
//				canvas.drawOval(oval, paint);
			}
			
		}
		return super.draw(canvas, mapView, shadow, when);
	}//end of draw method

}


